﻿<%@ WebHandler Language="C#" Class="vote" %>

using System;
using System.Web;
using System.Data.OleDb;
using System.Data;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Web.Security;
using System.Text;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

public class vote : IHttpHandler
{
    
    public void ProcessRequest (HttpContext context) {

        //指定接收数据的类型(解包)
        context.Response.ContentType = "application/json";
        //接收数据(存入变量)
        string pname = context.Request["pname"],
        pno = context.Request["pno"],
        page = context.Request["page"],
        sex = context.Request["sex"],
        pdep = context.Request["pdep"],
        pclass = context.Request["pclass"],
        pdno = context.Request["pdno"],
        pemail = context.Request["pemail"],
        webid = context.Request["webid"],
        preason = context.Request["preason"];


        int result = insertData(pname, pno, page, sex, pdep, pclass, pdno, pemail, webid, preason);

        context.Response.Write(result);
    }

    public int insertData(string votername, string sno, string age, string sex, string department, string classname, string idcard, string email, string webid, string reason)
    {

        try
        {

            string inserSql = String.Format(" insert into voteList(votername,sno,age,sex,idcard,department,class,email,webid,reason) " +
                " values('{0}','{1}',{2},'{3}','{4}','{5}','{6}','{7}',{8},'{9}') ",
                votername, sno, age, sex, idcard, department, classname, email, webid, reason);

            string updateSql = String.Format("update web set getvotes = getvotes+1 where id={0}", webid);
            DBHelper.sqlMethodNoDataset(updateSql);
            return DBHelper.sqlMethodNoDataset(inserSql);
        }
        catch (Exception e)
        {
            return 0;
        }
    }
    
    public bool IsReusable {
        get {
            return false;
        }
    }

}